var $ = getApp(), methods = require("../methods.js");
Page(Object.assign({}, methods, {
	data: {
		addressList: [],
		isload: 0,
	},
	_onLoad:function(){
		var that = this;
		$.get('address/address', {type:that.options.type}, function (data) {
			var list = data.list
			if(list.length == 0){
				wx.redirectTo({url:'/pages/address/addressadd?type='+data.type})
			}
			that.setData(data);
			that.setData({type:that.options.type});
			that.setData({ 'isload': 1 });
		})
	},
	//选择收货地址
	setdefault: function (e) {
		var that = this;
		var fromPage = this.options.fromPage;
		var addressId = e.currentTarget.dataset.id;
		$.post('address/setdefault', {addressid: addressId}, function (data) {
			console.log(fromPage)
			if(fromPage){
				$.goback(true);
			}else{
				that._onLoad();
			}
		});
	},
	del:function(e){
		var that = this;
		var addressId = e.currentTarget.dataset.id;
		console.log(addressId)
		$.confirm('确定要删除此地址吗?',function(){
			$.post("address/del",{addressid:addressId},function(res){
				$.success(res.msg);
				that._onLoad();
			});
		})
	}
}));